﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Data.MultiTenancy/ConfigurationTenantResolver 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       ConfigurationTenantResolver
* 创建时间：  2025/5/24 8:59:56
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using SSPivot.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.Data.MultiTenancy
{
    // 5. 基于配置文件的租户解析实现
    public class ConfigurationTenantResolver : ITenantResolver
    {
        private readonly IHttpContextAccessor _httpContextAccessor;

        private readonly IConfiguration _config;

        public ConfigurationTenantResolver(IHttpContextAccessor httpContextAccessor, IConfiguration config)
        {
            _config = config;
        }

        public Task<Tenant> ResolveTenant(string tenantIdentifier)
        {
            var tenantId = _httpContextAccessor.HttpContext?.Request.Headers["TenantId"].FirstOrDefault();
            //return tenantId != null ? await _tenantStore.GetTenantAsync(tenantId) : null;

            //return Task.FromResult(new Tenant
            //{
            //    Id = tenantIdentifier,
            //    Name = tenantSection["Name"],
            //    DbType = Enum.Parse<DatabaseType>(tenantSection["DbType"]),
            //    ConnectionString = tenantSection["ConnectionString"]
            //});
            return null;
        }
    }
}
